package org.bf.sms.domain.common;

import java.util.HashMap;
import java.util.Map;

import org.bf.sms.util.JSONTranslator;

/**
 * AJAX result bean
 * 
 * @author LiuChang 2010-12-14
 * @version 1.0
 * @since 1.0
 */
public class JSONResponse
{

	/** result code */
	private String code;

	/** result message */
	private String message;

	/** result object */
	private String json;

	/**
	 * constructor
	 */
	public JSONResponse()
	{
		super();
	}

	/**
	 * constructor
	 */
	public JSONResponse(String code, String message, String json)
	{
		super();
		this.code = code;
		this.message = message;
		this.json = json;
	}

	/**
	 * return the JSON string
	 */
	@Override
	public String toString()
	{
		return JSONTranslator.toJSON(this);
	}

	/**
	 * return map
	 * 
	 * @return response information
	 */
	public Map<String, Object> toMap()
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", this.code);
		map.put("message", this.message);
		map.put("json", this.json);
		return map;
	}

	/**
	 * return map
	 * 
	 * @return response information
	 */
	public Map<String, Object> toMap(Class<?> clazz)
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", this.code);
		map.put("message", this.message);
		map.put("json", JSONTranslator.toBean(this.json, clazz));
		return map;
	}

	/**
	 * @return the code
	 */
	public String getCode()
	{
		return this.code;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public void setCode(String code)
	{
		this.code = code;
	}

	/**
	 * @return the message
	 */
	public String getMessage()
	{
		return this.message;
	}

	/**
	 * @param message
	 *            the message to set
	 */
	public void setMessage(String message)
	{
		this.message = message;
	}

	/**
	 * @return the json
	 */
	public String getJson()
	{
		return this.json;
	}

	/**
	 * @param json
	 *            the json to set
	 */
	public void setJson(String json)
	{
		this.json = json;
	}

}
